package com.jieao.front.controller;

import com.jieao.common.core.controller.BaseController;
import com.jieao.common.core.domain.AjaxResult;
import com.jieao.content.domain.ArticleComment;
import com.jieao.content.domain.ArticleCommentLike;
import com.jieao.content.dto.ArticleCommentDto;
import com.jieao.content.dto.ArticleDto;
import com.jieao.content.service.IArticleCommentLikeService;
import com.jieao.content.service.IArticleCommentService;
import com.jieao.content.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Description 文章页面 控制器
 * @Author weifanl
 * @Date2020/7/12 13:14
 **/
@Controller
@RequestMapping("/front/article")
public class FrontArticleController extends BaseController {
    @Autowired
    private IArticleService articleService;
    @Autowired
    private IArticleCommentService articleCommentService;
    @Autowired
    private IArticleCommentLikeService articleCommentLikeService;
    /**
     * 文章详情页文章
     * @param articleId
     * @param mmap
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @GetMapping(value = "/articleDetil")
    public String articleDetil(Long articleId, ModelMap mmap) {
        ArticleDto article = articleService.selectArticleById(articleId);
        mmap.put("article", article);
        return "front/article";
    }

    /**
     * 喜欢文章
     * @param articleId
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @GetMapping(value = "/articleLike")
    @ResponseBody
    public AjaxResult articleLike(Long articleId) {
        Integer count = articleService.articleLike(articleId);
        return AjaxResult.success();
    }

    /**
     * 获取文章评论
     * @param articleId
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @GetMapping(value = "/selectCommentList")
    @ResponseBody
    public AjaxResult selectCommentList(Long articleId) {
        List<ArticleCommentDto> commentList = articleCommentService.selectCommentList(articleId);
        return AjaxResult.success(commentList);
    }

    /**
     * 发送文章评论
     * @param comment
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @PostMapping(value = "/pushComment")
    @ResponseBody
    public AjaxResult pushComment(@RequestBody ArticleComment comment) {
        articleCommentService.insertComment(comment);
        comment.setCreateTime(new Date());
        return AjaxResult.success(comment);
    }

    /**
     * 文章评论点赞
     * @param commentLike
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @PostMapping(value = "/insertCommentLike")
    @ResponseBody
    public AjaxResult insertCommentLike(@RequestBody ArticleCommentLike commentLike) {
        return articleCommentLikeService.insertCommentLike(commentLike);
    }

}
